package com.woniuxy.main.service.impl;

import com.woniuxy.main.mapper.StaffMapper;
import com.woniuxy.main.pojo.Staff;
import com.woniuxy.main.service.StaffService;
import org.apache.shiro.crypto.hash.SimpleHash;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import sun.java2d.pipe.SpanIterator;

import java.sql.SQLOutput;
import java.util.List;

/*
 *
 *  @author zhc
 *  @create 2019-08-01 9:55
 */
@Service
@Transactional
public class StaffServiceImpl  implements StaffService {
    @Autowired
    StaffMapper staffMapper;
    @Override
    public List<Staff> findAll() {
        List<Staff> staffs = staffMapper.findAll();

        return staffs;
    }

    @Override
    public int sRepeated(String saccount) {

        int b=staffMapper.sRepeated(saccount);

        return b;
    }

    @Override
    public Boolean addStaff(Staff staff) {

        //MD5加密
        staff.setSpassword(new SimpleHash("MD5", staff.getSaccount(),staff.getSname(), 1024).toString());

        Boolean staff1 = staffMapper.addStaff(staff);
        return staff1;
    }

    @Override
    public Staff selectStaffBySaccount(String saccount) {
        Staff staff=staffMapper.selectStaffBySaccount(saccount);

        return staff;
    }

    @Override
    public boolean updateStaff(Staff staff) {

        staff.setSpassword(new SimpleHash("MD5", staff.getSpassword(),staff.getSaccount(), 1024).toString());
        boolean b=staffMapper.updateStaff(staff);

        return b;
    }

    @Override
    public boolean delStaff(int id) {
        boolean b=staffMapper.delStaff(id);

        return b;
    }

    @Override
    public List<Staff> findByCondition(Staff staff) {

        List<Staff> byCondition = staffMapper.findByCondition(staff);

        return byCondition;
    }

    @Override
    public Staff selectStaffById(int id) {

       Staff staff = staffMapper.selectStaffById(id);

        return staff;
    }

    @Override
    public boolean findpass(Staff staff) {

        staff.setSpassword(new SimpleHash("MD5", staff.getSpassword(),staff.getSaccount(), 1024).toString());

        Staff staff1 = selectStaffById(staff.getStaff_id());

//        System.out.println(staff.getSpassword()+"*/*/*");
//        System.out.println(staff1.getSpassword()+"*/*/*");
        if (staff.getSpassword().equals(staff1.getSpassword())){
            return true;
        }

        return false;
    }

}
